package com.xinqi.modules.course.clazz.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.course.clazz.client.ClassGroupClient;
import com.xinqi.modules.course.clazz.dto.rsp.ClassGroupResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 班级分组表降级处理
 *
 * @author: system
 * @date: 2023/10/31
 */
@Slf4j
@Component
public class ClassGroupFallbackFactory implements FallbackFactory<ClassGroupClient> {

    @Override
    public ClassGroupClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new ClassGroupClient() {

            @Override
            public R<ClassGroupResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<List<ClassGroupResultDTO>> selectList(List<Long> groupIds) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

        };
    }
}
